
define(['vue','config','common'],function(Vue,config,utils){
	'use strict';

	var bankView=new Vue({
		el:'#app',
		data:{
			items:[],
			isRealName:''
		},
		created:function(){
			utils.userToken();

	        //获取银行卡列表
	        var _this=this;
	        _this.cardType=1;
	        var data = {
	        	cardType: _this.cardType
	        };
	        utils.ajax(utils.getWebUrl('bankard/list'),data,'POST',function(res){
	        	//console.log(res)
	        	_this.items = res.data;
	        	utils.ajax(utils.getWebUrl('user/personal'),null,'POST',function(res){
		        	_this.isRealName = res.data.isRealName;
		        })
	        },function(){
				$('.DataLoading').show();
			},function(){
				$('.DataLoading').hide();
			})
            
		},
		methods:{
			selectDefault:function(event){
				//console.log($target.parents('.bankList').data('id'))
				var $target = $($(event.currentTarget).find('span'));
				utils.checked($target);
				utils.unchecked($target.parents('.bankList').siblings().find('span'));

				var id = $target.parents('.bankList').data('id');				
				utils.ajax(utils.getWebUrl('bankard/setDefault'),{
					id:id
				},'POST',function(res){
					$target.parents('.bankList').find('.del').hide();;
					$target.parents('.bankList').siblings().find('.del').show();
				})
			},
			delectCard:function(event){

				var $target = $(event.currentTarget);
				var id = $target.parents('.bankList').data('id');	
				utils.appAlert('确定要删除此卡?',function(){
					utils.ajax(utils.getWebUrl('bankard/delete'),{
						id: id
					},'POST',function(res){
						utils.appAlert('删除成功',function(){
							$target.parents('.bankList').hide();
						})
					})
				})		
			},
			//window.location.href='AddBank.html'
			toAddBank: function(){
				if(this.isRealName == 2){
					window.location.href='AddBank.html'
				}else{
					utils.appAlert('请先实名认证',null,'取消',function(){
						window.location.href = 'certification.html?type=2'
					},'确定');
				}
			}
		}
	})

	return bankView
});